
  function goBack() {
    window.history.back();
  }
  
  // 获取全部的密码框和确认支付按钮
  const passwordInputs = document.querySelectorAll('.password-box');
  const submitButton = document.getElementById('submit-button');

  // 检查所有输入框是否都被填写了
  function checkInputs() {
    for (let i = 0; i < passwordInputs.length; i++) {
      if (passwordInputs[i].value === '') {
        submitButton.disabled = true;
        return; // 提前退出，如果发现空的输入框
      }
    }
    // 如果所有的输入框都填写了，激活确认支付按钮
    submitButton.disabled = false;
  }

  // 密码框填写逻辑和自动跳转到下一个输入框
  passwordInputs.forEach((input, index, inputs) => {
    input.addEventListener('input', (event) => {
      if (event.target.value.length > 1) {
        event.target.value = event.target.value[0]; // 只允许一个字符
      }

      // 检查是否启用按钮
      checkInputs();

      // 跳转到下一个输入框
      if (event.target.value.length === 1 && index < inputs.length - 1) {
        inputs[index + 1].focus();
      }
    });

    // 当前面的输入框被删除内容移到前面的框
    input.addEventListener('keyup', (event) => {
      if (event.key === 'Backspace' && index > 0 && inputs[index].value === '') {
        inputs[index - 1].focus();
      }
    });
  });

  // 弹窗逻辑
  const paymentSuccessModal = document.getElementById('paymentSuccessModal');
  const closeButton = document.querySelector('.close');

  submitButton.addEventListener('click', () => {
    paymentSuccessModal.style.display = 'block';
  });

  closeButton.addEventListener('click', () => {
    paymentSuccessModal.style.display = 'none';
  });

  // 点击窗口外面关闭弹窗
  window.addEventListener('click', (event) => {
    if (event.target === paymentSuccessModal) {
      paymentSuccessModal.style.display = 'none';
    }
  });

  // 以下是用于最后的弹窗弹出功能的代码
 document.addEventListener('DOMContentLoaded', (event) => {
   const myButton = document.getElementById('myButton');
   const popupContainer = document.getElementById('popupContainer');
   const closeButton = document.getElementById('closeButton');
 
   // 封装动画结束后的处理功能
   function handleAnimationEnd(popupContent) {
     popupContent.addEventListener('animationend', function handler() {
       popupContainer.style.display = 'none';
       popupContent.classList.remove('closing');
       popupContent.removeEventListener('animationend', handler); // 移除事件监听器，避免重复和积累
     }, { once: true }); // 使用 { once: true } 使事件只触发一次
   }
 
   // 显示弹出层
   myButton.addEventListener('click', () => {
     popupContainer.style.display = 'block';
     const popupContent = popupContainer.querySelector('.popup-content');
     popupContent.classList.remove('closing');
   });
 
   // 隐藏弹出层
   closeButton.addEventListener('click', () => {
     const popupContent = popupContainer.querySelector('.popup-content');
     popupContent.classList.add('closing'); // 添加关闭类以启动动画
     handleAnimationEnd(popupContent);
   });
 
   // 点击窗口外面也应当关闭弹窗
   window.addEventListener('click', (event) => {
     if (event.target === popupContainer) {
       const popupContent = popupContainer.querySelector('.popup-content');
       popupContent.classList.add('closing'); // 添加关闭类以启动动画
       handleAnimationEnd(popupContent);
     }
   });
 });